﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for HANGXE_DATAACCESS
/// </summary>
public class HANGXE_DATAACCESS
{
    private static string sp_Name = "sp_HANGXE";
    public static void ExcuteQueryString(string ACTION, HANGXE_ENTITY hx)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (hx != null)
            {
                com.Parameters.AddWithValue("MAHANG", hx.MAHANG);
                com.Parameters.AddWithValue("TENHANG", hx.TENHANG);
                com.Parameters.AddWithValue("QUOCGIA", hx.QUOCGIA);
               
            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            com.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    public static DataSet GETDATATABLE(string ACTION, HANGXE_ENTITY hx)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        DataSet ds;
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (hx != null)
            {
                com.Parameters.AddWithValue("MAHANG", hx.MAHANG);
                com.Parameters.AddWithValue("TENHANG", hx.TENHANG);
                com.Parameters.AddWithValue("QUOCGIA", hx.QUOCGIA);

            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
            return new DataSet();
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
   
}